<?php

class App_Controller_Action extends Zend_Controller_Action
{
    public function init()
    {
        $this->_session = Zend_Registry::get('session');
        $this->view = Zend_Registry::get('view');
        $this->view->request = $this->getRequest();
        $module = ucfirst($this->getRequest()->getModuleName());
        $this->view->setBasePath(APPLICATION_PATH . "/code/Core/views/");
        $this->view->addBasePath(APPLICATION_PATH . "/code/{$module}/views/");

        $this->view->headScript()->appendFile(BASE_URL . '/js/lib/json2.js');
        $this->view->headLink()->appendStylesheet(BASE_URL . '/css/styles.css');

        $this->view->base_url = BASE_URL;
    }

    public function sendSuccess()
    {
        $this->_helper->json->sendJson(array('success' => true));
    }

    public function sendErrors($errors)
    {
        if (!is_array($errors)) {
            $errors = array($errors);
        }
        $this->_helper->json->sendJson(array(
            'success' => false,
            'errors' => $errors
        ));
    }
}